import Estimation.nlpm as nlpm
from tqdm import tqdm


def calc_measure(graph, start_time, estimate_type='cn'):
    vertices = graph.vertices
    estimator = None
    if estimate_type == 'cn':
        estimator = nlpm.cn_wt
    for u in tqdm(vertices):
        neighbors_u, directions_u, edges_u = u.get_neighbor()
        u_id = u.identity
        for (z, z_d, z_e) in zip(neighbors_u, directions_u, edges_u):
            node_z = graph.vertices[graph.vertex_index[z]]
            neighbors_z, directions_z, edges_z = node_z.get_neighbor()
            for (v, v_d, v_e) in zip(neighbors_z, directions_z, edges_z):
                if u_id == v:
                    continue
                pattern = match_pattern(z_d, v_d)
                score = estimator(z_e, v_e, start_time)
                u.add_measure(v, pattern, score)


def match_pattern(z_d, v_d):
    return z_d * v_d
